<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>验证码</title>
    <!--<script src="../META-INF.resources/jquery/jquery-3.2.1.min.js"></script>-->
</head>
<body>

<div id="checkCode">
    验证码
    <a><img style="cursor:pointer;" onclick="changeImgs()" id="changeCode" src="http://localhost:7000/kaptcha/getKaptchaImage"/></a>
</div>

</body>
</html>
<script type="application/javascript">
    var api_url = getRootPath()+"/";
    function refresh(obj){
        obj.src = api_url + "kaptcha/getKaptchaImage";//?" + Math.random()
        console.log("obj.src = "+ obj.src);
    }

    /*$(function () {
     $("#changeCode").click(function(){
     refresh(this);
     });
     });*/
    /* window.onload = function(){
     console.log("onload: ");
     document.getElementById("changeCode").click(function(){
     refresh(this);
     console.log("refresh: ");
     })
     };*/

    function changeImgs() {
//        refresh(this);
        document.getElementById("changeCode").setAttribute("src", "http://localhost:7000/kaptcha/getKaptchaImage");
        console.log("refresh: ");
    }

    function getRootPath(){
        var strFullPath = window.document.location.href;
        var pre = "";
        var basePath = "";
        if(strFullPath.indexOf("https://")!=-1){
            basePath = "https://";
            pre = strFullPath.substring(basePath.length, strFullPath.length);
        }else{
            basePath = "http://";
            pre = strFullPath.substring(basePath.length, strFullPath.length);
        }
        var str = pre.split("/");
        return basePath+str[0];
    };

</script>
